package com.kj.report.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jayway.jsonpath.JsonPath;
import com.kj.common.exception.RestException;

import com.kj.common.response.Response;
import com.kj.common.util.StringUtils;
import com.kj.member.model.Customer;
import com.kj.member.interfaces.CustomerInfoRMI;
import com.kj.report.mapper.DeviceMapper;
import com.kj.report.mapper.DeviceUserRelationMapper;
import com.kj.report.model.*;
import com.kj.report.mongoRepository.ReportViewRepository;
import com.kj.report.service.InspectResultBaseInfoService;
import com.kj.report.service.ReportOrderService;
import com.kj.report.service.ReportV2Service;
import com.kj.report.utils.*;

import com.kj.report.utils.enumUtil.IndexIconUrl;
import org.apache.http.client.ClientProtocolException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportV2ServiceImpl implements ReportV2Service{
    Logger logger = Logger.getLogger(ReportV2ServiceImpl.class);

    @Resource
    private PropertiesUtil propertiesUtil;

    @Resource
    private RedisCache redisCache;

    @Resource
    private ReportViewRepository reportViewRepository;

    @Resource
    private WeChatServiceImpl weChatServiceImpl;

    @Resource
    private ReportOrderService reportOrderService;

    @Resource
    private CustomerInfoRMI customerInfoRMI;

    @Resource
    private RedisUtils redisUtils;

    @Resource
    private DeviceMapper deviceMapper;

    @Resource
    private DeviceUserRelationMapper deviceUserRelationMapper;

    @Resource
    private InspectResultBaseInfoService inspectResultBaseInfoService;

    @Resource
    private HealthAdviceServiceImpl healthAdviceServiceImpl;

    @Value("${agent.kjAgentId}")
    private String agentId;
    @Value("${agent.kjAgentKey}")
    private String agentKey;
    @Value("${robot.baseUrl}")
    private String url;
    @Value("${recipes.url}")
    private String recipesUrl;

    /**
     * 解析2.0报告--mn
     * @param customer
     * @param reportId
     * @param isSend
     * @param openId
     * @param urlType
     * @param clientType
     * @return
     */

    public Response analysisReports(Customer customer, String reportId, boolean isSend, String openId, String urlType, String clientType) {
          logger.info(reportId + "解析报告方法isSend：" + isSend + "、openId：" + openId + "、customer:" + customer.getCustomerId());
          //系统当前时间
          long startTime = System.currentTimeMillis();

          String redisReportId = (String) redisCache.select("analysisReport:" + reportId);redisCache.select("analysisReport:" + reportId);
          Integer reportX = Integer.parseInt(propertiesUtil.getReportAge());//年龄
          Map<String,String> paramMap = Maps.newHashMap();
          paramMap.put("uId",String.valueOf(customer.getCustomerId()));
          paramMap.put("reportId",reportId);
          String results="";

          try {
              String param = HttpUtils.buildUrl(propertiesUtil.getAnalysisReport()+"v2/reportData/createReportData", paramMap);
              results= HttpUtils.sendPostNotParam(param);
              String code =  String.valueOf(JsonPath.read(results,"$.code"));
              if (!code.equals("200"))
                  return null;

          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }

          //获取报告数据
          ReportView byId = reportViewRepository.findById(reportId);
          long endTime = System.currentTimeMillis();
          logger.info("<-- 从开始解析到数据存入mongo用时："+(endTime-startTime)+"毫秒 -->");
          //判断来源
          if(clientType.equals("wx")){

          /** 发送图文消息 */
          String errcode = "";
          if (isSend) {
              String result = weChatServiceImpl.sendReportMsg(reportId, openId, customer.getNickName(), byId.getInspectDate(), String.valueOf(byId.getDeviceType()), byId.getReportType());
              JSONObject jsonObject = JSONObject.parseObject(result);
              errcode = jsonObject.get("errcode")+"";
              logger.info(reportId+"解析报告成功发送图文消息结果："+result);
          }
          }
          //生成订单
          reportOrderService.inserPayOrder(reportId, byId.getDeviceId(), customer.getCustomerId());

          return null;
        }

    @Override
    public Response<?> reportV2Generation(Long customerId, String reportId) {
        ReportView report = this.reportViewRepository.findById(reportId);
        if (report != null){
           throw new RestException(103,"报告已存在");
        }

        //获取用户信息customer
        Response<Customer> customerResult = customerInfoRMI.queryCustomerById(customerId);

        Customer userInfo = customerResult.getResult();
        //判断用户
        if (userInfo!=null){
            //throw new RestException();
        }
        //生成报告的数据
        ReportView reportView = new ReportView();
        //获取token
        String tokenKey = ReportBaseUtil.getTokenKey(redisUtils, url, agentId,agentKey);
        //获取指标数据
        String indicators = ReportBaseUtil.getIndicators(redisUtils, url, tokenKey);
        //老版建议
        String stanPropose = ReportBaseUtil.getStanPropose(redisUtils, url, tokenKey);
        //获取新版建议数据
        String newPropose = ReportBaseUtil.getNewPropose(redisUtils, url, tokenKey);
        //获取报告数据
        String reportData = ReportBaseUtil.getReportData(url, reportId, userInfo.getAge(), String.valueOf(userInfo.getCustomerId()),tokenKey);
        if(StringUtils.isEmpty(indicators)
                || StringUtils.isEmpty(stanPropose)
                || StringUtils.isEmpty(newPropose)
                || StringUtils.isEmpty(reportData)){
            //没有原始数据
            return null;
        }
        Integer read = JsonPath.read(reportData, "$.code");
        if (read != 0){
            //没有原始数据
            return null;
        }

        // 获取设备信息
        Device device = new Device();
        String read1 = JsonPath.read(reportData, "$.data.robotSn");
        device.setSnNum(read1);//设备sn
        Device deviceInfo = this.deviceMapper.selectDeviceObjSingle(device);

        reportView.setInspectId(reportId);//报告Id
        reportView.setUserId(DataTransitionUtil.longToInteger(userInfo.getCustomerId()));//userId
        reportView.setTotalScore(JsonPath.read(reportData,"$.data.totalScore"));//报告分数
        Integer gender = JsonPath.read(reportData, "$.data.gender");
        reportView.setTitleSex("亲爱的"+userInfo.getNickName()+(gender == 1?"先生":"女士"));
        Date date = new Date();
        reportView.setInspectDate(date);//系统当前时间
        reportView.setInspectDateStr(ReportBaseUtil.getTimestampStr(date));
        reportView.setAge(JsonPath.read(reportData,"$.data.inspectAge"));//报告年龄
        reportView.setInspectType(deviceInfo.getDeviceReport());//报告类型 设备报告类型 1 正常版 2 简版 3 详细建议 4 桌面机 5 改善分析  6 3.0版 100 公益*/
        reportView.setIsCharge(DataTransitionUtil.longToInteger(deviceInfo.getDeviceTypeId()));//是否收费
        reportView.setReportType(deviceInfo.getDeviceReport());//报告类型
        reportView.setSex(JsonPath.read(reportData,"$.data.gender"));//性别
        reportView.setDeviceType(deviceInfo.getDeviceType());///*1 大机器 2 桌面机*/
        reportView.setDeviceSnNum(JsonPath.read(reportData,"$.data.robotSn"));/*设备sn码*/
        reportView.setDeviceMacAddress(JsonPath.read(reportData,"$.data.robotMac"));//设备mac
        reportView.setDeviceId(DataTransitionUtil.longToInteger(deviceInfo.getDeviceId()));//设备Id
        //分数排名，reprotType写死表示排名不分版本
        Integer ranking = inspectResultBaseInfoService.rankingUserScore(reportView.getTotalScore(), 5, reportView.getAge());
        reportView.setRanking(ranking);
       /* setAgentIds(deviceInfo,reportView);*/
        setAgentIds(deviceInfo,reportView);

        reportView.setSceneId(deviceInfo.getSceneId());//场景ID
        reportView.setSceneSecondId(deviceInfo.getSceneSecondId());//小场景ID
        List<Map<String, String>> recipesList = Lists.newArrayList();

//一级指标拼接
        List<Map<String,Object>>   firstdata= JsonPath.read(reportData, "$.data.firstTarget");
        HashMap<String,Object> indicatorsMap = JsonPath.read(indicators,"$.data");
        List<Map<String,Object>> psTarget=JsonPath.read(reportData,"$.data.psTargets");
        HashMap<String,Map<String,Object>> normMap=JsonPath.read(indicators,"$.data");
        //身体状况
        List<PhysicalConditionView> psList = ReportBaseUtil.getPsList(reportId, DataTransitionUtil.objToInteger(userInfo.getCustomerId()), deviceInfo, psTarget, normMap);
        reportView.setConditions(psList);	/*身体状况*/

        List<ImproveProposalView> improves = Lists.newArrayList();
        //标准建议数据
        Map<String,Object>  stanProposemap = JsonPath.read(stanPropose,"$.data");
        StringBuilder title  = new StringBuilder();
        StringBuilder titlesecond  = new StringBuilder();
        StringBuilder titlesthree  = new StringBuilder();
        String reportStr ="您的生理年龄<font>"+reportView.getAge()+"</font>岁，身体各系统生理年龄分别为：";
        reportView.setReportStr(reportStr);
        StringBuilder firstStr = new StringBuilder();
        title.append("您好！本次对您的健康评估您在");
        List<ReportFirstView> reportFirstViews = reportDataAssembly(firstdata, reportId, DataTransitionUtil.objToInteger(userInfo.getCustomerId()),
                indicatorsMap, deviceInfo, firstStr,
                stanProposemap, titlesecond, titlesthree,
                improves, newPropose,recipesList,reportView.getSex());
        //食谱
        String recipes = ReportBaseUtil.getRecipes(recipesUrl, recipesList, reportId);
        reportView.setRecipesStr(recipes);//食谱数据
        reportView.setFirsts(reportFirstViews);//private List<ReportFirstView> firsts;			/*一级指标*/
        reportView.setImproves(improves);//private List<ImproveProposalView> improves;		/*改善建议*/
        if (titlesecond != null && titlesthree != null){
            reportView.setHeadIndex(title+titlesecond.toString()+"处于亚健康状态，"+titlesthree);
        }
        reportView.setFirstStr(String.valueOf(firstStr));
        reportViewRepository.insert(reportView);
        logger.info("userId : "+userInfo.getCustomerId()+"-- reportId : "+reportId+" 插入mongo完成");
        //addInspectDdsScore(reportView);
        logger.info("userId : "+userInfo.getCustomerId()+"-- reportId : "+reportId+" 插入inspect_dds_score完成");
       // addInspectResultBaseInfo(reportView,userInfo);
        logger.info("userId : "+userInfo.getCustomerId()+"-- reportId : "+reportId+" 插入inspect_result_base_info完成");





        return null;
    }

    private void setAgentIds(Device deviceInfo,ReportView reportView){
        String agentIds = "1";
        String provinceIds = ",";
        String cityIds = "";
        DeviceUserRelation deviceUserRelation = new DeviceUserRelation();
        deviceUserRelation.setDeviceId(DataTransitionUtil.longToInteger(deviceInfo.getDeviceId()));

        List<DeviceUserRelation> durs = deviceUserRelationMapper.selectList(deviceUserRelation);
        if (durs != null && durs.size() > 0) {
            for (DeviceUserRelation dur : durs) {
                if (dur.getIsBuyers() == 1) {
                    reportView.setAgentId(dur.getUserId()+"");//代理人Id
                    provinceIds += dur.getUserId();
                }else if (dur.getIsBuyers() == 2) {
                    cityIds += ","+dur.getUserId();
                }
            }
        }
        reportView.setAgentIds(agentIds + provinceIds + cityIds);
    }

    public List<ReportFirstView> reportDataAssembly(List<Map<String,Object>> firstdata,String reportId,Integer userId,
                                                    HashMap<String,Object> indicatorsMap,Device deviceInfo,StringBuilder firstStr,
                                                    Map<String,Object>  stanProposemap,StringBuilder titlesecond,StringBuilder titlesthree,
                                                    List<ImproveProposalView> improves,String newPropose,List<Map<String, String>> recipesList,Integer genderId){
        //一级指标遍历
        List<ReportFirstView> reportFirstList = firstdata.stream().map(
                param -> {
                    ReportFirstView reportFirstView = new ReportFirstView();
                    reportFirstView.setInspectId(reportId);//报告Id
                    reportFirstView.setUserId(userId);//用户Id
                    reportFirstView.setTargetId(DataTransitionUtil.objToInteger(param.get("targetId")));//指标Id

                    //指标名称
                    String firsttargetId = param.get("targetId")==null?null:JsonPath.read(indicatorsMap.get(param.get("targetId").toString()), "$.name");
                    reportFirstView.setTargetName(firsttargetId);
                    //指标解释
                    Object targetId = param.get("targetId");
                    Object o = indicatorsMap.get(targetId.toString());
                    String read = JsonPath.read(o, "$.explain");

                    reportFirstView.setExplain(firsttargetId==null?null:JsonPath.read(indicatorsMap.get(String.valueOf(param.get("targetId"))), "$.explain"));
                    //分数
                    reportFirstView.setScore(DataTransitionUtil.objToInteger(param.get("score")));
                    reportFirstView.setVisibility(1);/*是否可见：1可见；2不可见*/
                    ///*生理年龄*/
//                    reportFirstView.setPhysiologicalAge(param.get("inspectAge")==null?null:Integer.valueOf(param.get("inspectAge").toString()));
                    reportFirstView.setPhysiologicalAge(DataTransitionUtil.objToInteger(param.get("inspectAge")));
                    firstStr.append("<span>"+reportFirstView.getTargetName()+param.get("inspectAge")+"岁;&nbsp;</span>");
                    reportFirstView.setIconUrl(IndexIconUrl.getEnumByKey(reportFirstView.getTargetId()));//图片地址
                    reportFirstView.setDeviceType(deviceInfo.getDeviceType());/*1 大机器 2 桌面机*/
                    //解析二级目录
                    List<Map<String, Object>> secondTarget = JsonPath.read(param.get("secondTarget"), "$");
                    List<ReportSecondView> collect1 = secondTarget.stream().map(
                            secondTargetparam -> {
                                ReportSecondView reportSecondView = new ReportSecondView();
                                reportSecondView.setInspectId(reportId);//报告Id
                                reportSecondView.setUserId(DataTransitionUtil.objToInteger(userId));//用户Id
                                reportSecondView.setTargetId(DataTransitionUtil.objToInteger(secondTargetparam.get("targetId")));//指标Id

                                reportSecondView.setTargetName(JsonPath.read(indicatorsMap.get(String.valueOf(secondTargetparam.get("targetId"))), "$.name"));//指标名称
                                //指标解释
                                reportSecondView.setExplain(JsonPath.read(indicatorsMap.get(String.valueOf(secondTargetparam.get("targetId"))),"$.explain"));
                                reportSecondView.setScore(DataTransitionUtil.objToInteger(secondTargetparam.get("score")));//分数
                                //对应检查结果的一级指标
                                reportSecondView.setResultFirstId(DataTransitionUtil.objToInteger(param.get("targetId")));

                                reportSecondView.setDeviceType(deviceInfo.getDeviceType());//	/*1 大机器 2 桌面机*/
                                //解析三级目录
                                List<Map<String, Object>> threeTargetMap = JsonPath.read(secondTargetparam.get("threeTarget"), "$");
                                //监控子循环次数
                                List<String> arr = Lists.newArrayList();

                                List<ReportThirdView> collect = threeTargetMap.stream().map(
                                        threeTarget -> {
                                            Map<String,String> recipesMap = new HashMap<String, String>();
                                            //拼接食谱参数
                                            recipesMap.put("targetId", threeTarget.get("targetId")+"");
                                            recipesMap.put("score", threeTarget.get("score")+"");
                                            recipesMap.put("abnormalLevel", threeTarget.get("abLevel")==null? "1" : threeTarget.get("abLevel")+"");
                                            recipesMap.put("inspectStandard", threeTarget.get("offset")== null ? "1" : threeTarget.get("offset")+"");
                                            recipesList.add(recipesMap);
                                            ReportThirdView reportThirdView = new ReportThirdView();
                                            reportThirdView.setInspectId(reportId);//报告Id
                                            reportThirdView.setUserId(DataTransitionUtil.objToInteger(userId));//用户Id
                                            reportThirdView.setTargetId(DataTransitionUtil.objToInteger(threeTarget.get("targetId")));//指标id
                                            //指标名称
                                            reportThirdView.setTargetName(JsonPath.read(indicatorsMap.get(String.valueOf(threeTarget.get("targetId"))),"$.name"));
                                            //指标解释
                                            reportThirdView.setExplain(JsonPath.read(indicatorsMap.get(String.valueOf(threeTarget.get("targetId"))), "$.explain"));
                                            reportThirdView.setScore(DataTransitionUtil.objToInteger(threeTarget.get("score")));
                                            //reportThirdView.setMeasuredValue();//测量值
                                            Object abLevel = threeTarget.get("abLevel");
                                            reportThirdView.setAbnormalLevel(DataTransitionUtil.objToInteger(threeTarget.get("abLevel")));/*异常程度 1正常 2 轻度 3(4) 中度 5 重度*/
                                            reportThirdView.setInspectStandard(DataTransitionUtil.objToInteger(threeTarget.get("offset")));///* 检查标准// （正常/偏高/偏低）*/
                                            reportThirdView.setNewScore(DataTransitionUtil.objToInteger(threeTarget.get("score")));//原分数
                                            reportThirdView.setResultSecondId(DataTransitionUtil.objToInteger(secondTargetparam.get("targetId")));//二级父指标Id
                                            reportThirdView.setStatus(1);//状态

                                            reportThirdView.setTargetIndex(1);///*1 普通 2 重点*/未知默认是1
                                            reportThirdView.setDeviceType(deviceInfo.getDeviceType());///*1 大机器 2 桌面机*/
                                            HealthAdviceView healthAdviceView = new HealthAdviceView();
                                            Map<String,Object> s = (Map<String, Object>) stanProposemap.get(threeTarget.get("targetId") + "_" + threeTarget.get("offset"));
                                            if (deviceInfo.getGuideType() == 1) { //建议类型 1 老版 2 新版
                                                if (threeTarget.get("abLevel") !=null && DataTransitionUtil.objToInteger(threeTarget.get("abLevel")) > 3) {
                                                    //reportThirdView.setSuggestContent();//* 健康建议*/
                                                    //拼接建议二级
                                                    titlesecond.append(reportSecondView.getTargetName() + "、");
                                                    //三级建议拼接
                                                    if (arr.size() <= 0) {
                                                        titlesthree.append("其中" + reportSecondView.getTargetName() + "下的");
                                                        arr.add("1");
                                                    }
                                                    //拼接建议
                                                    titlesthree.append(reportThirdView.getTargetName());
                                                    if (reportThirdView.getInspectStandard() == 2)
                                                        titlesthree.append("偏低、");
                                                    else if (reportThirdView.getInspectStandard() == 3)
                                                        titlesthree.append("偏高、");
                                                    else
                                                        titlesthree.append("正常、");

                                                    ImproveProposalView improveProposalView = new ImproveProposalView();

                                                    improveProposalView.setTargetName(reportThirdView.getTargetName());/*指标名称*/
                                                    improveProposalView.setAbnormalLevel(reportThirdView.getAbnormalLevel());/*异常程度 1正常 2 轻度 3 中度 4 重度*/
                                                    improveProposalView.setInspectStandard(DataTransitionUtil.objToString(reportThirdView.getInspectStandard()));
                                                    improveProposalView.setGuideContent(JsonPath.read(s, "$.guideContent"));/*健康分析*/
                                                    improveProposalView.setSuggestContent(JsonPath.read(s, "$.suggestContent"));/*改善建议*/
                                                    if (s != null&s.get("program")!=null)
                                                        titlesthree.append("请您注意" + JsonPath.read(s, "$.program") + ";");
                                                    improves.add(improveProposalView);
                                                }
                                            } else {
                                                if (threeTarget.get("abLevel")!=null&&threeTarget.get("offset")!=null&&(DataTransitionUtil.objToInteger(threeTarget.get("abLevel")) > 1 & DataTransitionUtil.objToInteger(threeTarget.get("offset")) > 1)) {
                                                    //拼接建议二级
                                                    titlesecond.append(reportSecondView.getTargetName() + "、");
                                                    //三级建议拼接
                                                    if (arr.size() <= 0) {
                                                        titlesthree.append("其中" + reportSecondView.getTargetName() + "下的");
                                                        arr.add("1");
                                                    }
                                                    //拼接建议
                                                    titlesthree.append(reportThirdView.getTargetName());
                                                    if (reportThirdView.getInspectStandard() == 2)
                                                        titlesthree.append("偏低、");
                                                    else if (reportThirdView.getInspectStandard() == 3)
                                                        titlesthree.append("偏高、");
                                                    else
                                                        titlesthree.append("正常、");
                                                    if (s != null&&s.get("program")!=null)
                                                        titlesthree.append("请您注意" + JsonPath.read(s, "$.program") + ";");
                                                    List<TsIndexTypeView> dietList = Lists.newArrayList();// 膳食建议
                                                    List<TsIndexTypeView> nutritionList = Lists.newArrayList();// 营养建议
                                                    List<TsIndexTypeView> motionList = Lists.newArrayList();// 运动和生活方式建议
                                                    List<Map<String, Object>> propose = JsonPath.read(newPropose, "$.relation");
                                                    propose.stream().filter(proposeParam
                                                            -> {
                                                        return proposeParam.get("targetId") != null && (proposeParam.get("targetId").equals(threeTarget.get("targetId")) &
                                                                proposeParam.get("offset").equals(threeTarget.get("offset")));
                                                    }).forEach(proposeParam -> { /* 1 、膳食建议 2、营养 3、运动 */
                                                        //获取建议
                                                        List<Map<String, Object>> indexTypeIds = JsonPath.read(proposeParam.get("indexTypeIds"), "$");
                                                        indexTypeIds.stream().forEach(indexTypeIdsparam -> {
                                                            TsIndexTypeView tsIndexTypeView = new TsIndexTypeView();
                                                            tsIndexTypeView.setIndexTypeId(DataTransitionUtil.objToString(indexTypeIdsparam.get("indexTypeId")));
                                                            tsIndexTypeView.setSimpleDescription(DataTransitionUtil.objToString(indexTypeIdsparam.get("simpleDescription")));//建议描述
                                                            tsIndexTypeView.setIndexName(DataTransitionUtil.objToString(indexTypeIdsparam.get("indexName")));//指标名称
                                                            tsIndexTypeView.setIndexCode(DataTransitionUtil.objToString(indexTypeIdsparam.get("indexCode")));//指标code
                                                            tsIndexTypeView.setProposal(DataTransitionUtil.objToString(indexTypeIdsparam.get("proposal")));// /* 膳食建议 */
                                                            String personality = healthAdviceServiceImpl.scriptEngine(genderId, reportThirdView.getAbnormalLevel(),
                                                                    DataTransitionUtil.objToString(indexTypeIdsparam.get("expression")), DataTransitionUtil.objToString(indexTypeIdsparam.get("personality")));
                                                            tsIndexTypeView.setPersonality(personality);/* 个性化建议 */

                                                            if ("1".equals(String.valueOf(indexTypeIdsparam.get("indexType")))) {
                                                                nutritionList.add(tsIndexTypeView);
                                                            } else if ("2".equals(String.valueOf(indexTypeIdsparam.get("indexType")))) {
                                                                dietList.add(tsIndexTypeView);
                                                            } else if ("3".equals(String.valueOf(indexTypeIdsparam.get("indexType")))) {
                                                                motionList.add(tsIndexTypeView);
                                                            }
                                                        });
                                                    });
                                                    healthAdviceView.setDietList(dietList);
                                                    healthAdviceView.setMotionList(motionList);
                                                    healthAdviceView.setNutritionList(nutritionList);

                                                }
                                            }
                                            reportThirdView.setHealthAdviceVo(healthAdviceView);///* 指标详细建议*/
                                            return reportThirdView;
                                        }).collect(Collectors.toList());
                                reportSecondView.setThirds(collect);
                                return reportSecondView;
                            }).collect(Collectors.toList());
                    reportFirstView.setSeconds(collect1);

                    return reportFirstView;
                }).collect(Collectors.toList());
        return reportFirstList;
    }

}
